<template>
  <my-button @click="exportExcel" style="margin-left: 20px">点击导出</my-button>
</template>

<script>
  import MyButton from '../../../common/my-button'
  export default {
    name: 'index',
    components: { MyButton },
    methods:{
      exportExcel(){
        const headers = [
          'col1','col2','col3','col4','col5'
        ]
        const dataList = [
          {
            col1: '字段1',
            col2: '字段2',
            col3: '字段3',
            col4: '字段4',
            col5: '字段5',
          },{
            col1: '字段1',
            col2: '字段2',
            col3: '字段3',
            col4: '字段4',
            col5: '字段5',
          }
        ]
        import('@/util/Export2Excel').then(excel => {
          let exp = [];
          for(let item of dataList){
            let arr = [];
            for(let i in headers){
              arr.push(item[headers[i]])
            }
            exp.push(arr)
          }
          excel.export_json_to_excel({
            header: headers,
            data: exp,
            filename: '测试excel',
            autoWidth: true,
            bookType: 'xlsx'
          })
        })
      }
    }
  }
</script>

<style scoped>

</style>
